<template>
  <div class="button-setting">
    <el-tabs v-model="active">
      <el-tab-pane label="组件属性" name="first">
        <el-row type="flex" align="middle">
          <el-col :span="6">
            <div class="prop-set-title">字段标识</div>
          </el-col>
          <el-col :span="18">
           <select-model :model.sync="store.current.model"></select-model>
          </el-col>
        </el-row>

        <template v-if="store.current.options.isSelection">
          <el-row type="flex" align="middle">
            <el-col :span="6">
              <div class="prop-set-title">勾选事件</div>
            </el-col>
            <el-col :span="18">
              <el-select
                v-model="store.current.options.selectEventCode"
                placeholder="请选择事件名称"
              >
                <el-option
                  v-for="trigger in store.eventCollection"
                  :key="trigger.value"
                  :label="trigger.label"
                  :value="trigger.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </template>

        <template v-if="store.current.options.iseditor">
          <el-row type="flex" align="middle">
            <el-col :span="6">
              <div class="prop-set-title">操作按钮</div>
            </el-col>
            <el-col :span="18">
              <i
                @click="addHandles"
                class="el-icon-circle-plus-outline addForeignKey"
              ></i>
            </el-col>
          </el-row>

          <div class="handle-wrap">
            <el-card
              class="box-card"
              v-for="(handle, index) in store.current.handles"
              :key="'handles' + index"
            >
              <div slot="header" class="clearfix">
                <i
                  @click="removeBtn(store.current.handles, index)"
                  class="el-icon-delete"
                ></i>
              </div>
              <el-row type="flex" align="middle">
                <el-col :span="24">
                  <div class="prop-set-title">
                    <el-input
                      v-model="handle['name']"
                      placeholder="name"
                    ></el-input>
                  </div>
                </el-col>
              </el-row>
              <el-row type="flex" align="middle">
                <el-col :span="24">
                  <div class="prop-set-title">
                    <el-select
                      v-model="handle['eventCode']"
                      placeholder="请选择事件名称"
                      clearable
                    >
                      <el-option
                        v-for="trigger in store.eventCollection"
                        :key="trigger.value"
                        :label="trigger.label"
                        :value="trigger.value"
                      >
                      </el-option>
                    </el-select>
                  </div>
                </el-col>
              </el-row>
            </el-card>
          </div>
        </template>

      </el-tab-pane>
      <el-tab-pane label="表格属性" name="second">
        <el-row type="flex" align="middle">
          <el-col :span="8">
            <div class="prop-set-title">编辑表格</div>
          </el-col>
          <el-col :span="16">
            <el-radio-group v-model="store.current.options.iseditor">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-col>
        </el-row>

        <el-row type="flex" align="middle">
          <el-col :span="8">
            <div class="prop-set-title">是否多选</div>
          </el-col>
          <el-col :span="16">
            <el-radio-group v-model="store.current.options.isSelection">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-col>
        </el-row>

        <el-row type="flex" align="middle">
          <el-col :span="8">
            <div class="prop-set-title">固定操作列</div>
          </el-col>
          <el-col :span="16">
            <el-radio-group v-model="store.current.options.fixedright">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-col>
        </el-row>

      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import clone from "clone";
export default {
  inject: ["getStore"],
  data() {
    return {
      active: "first",
    };
  },
  methods: {
    addHandles() {
      this.store.current.handles.push({
        name: "",
        eventCode: "",
      });
    },
    removeBtn(handles, index) {
      handles.splice(index, 1);
    },
  },
  watch: {
    "store.current.options": {
      handler() {
        this.$handleStack.push(clone(this.store.root));
      },
      deep: true,
    },
  },
  computed: {
    store() {
      return this.getStore();
    },
    options() {
      return this.store.modelTree;
    },
  },
};
</script>

<style scoped>
::v-deep .el-tabs__item[aria-controls] {
  width: 50% !important;
  text-align: center;
}
.el-button {
  padding: 7px 15px;
}
.addForeignKey {
  font-size: 22px;
  cursor: pointer;
}

>>> .el-card__header {
  padding: 5px !important;
}
>>> .el-card {
  overflow: unset;
}
>>> .el-card__body {
  position: relative;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
.el-icon-delete {
  cursor: pointer;
  float: right;
  padding: 3px 0;
  color: red;
}

.handle-wrap {
  padding: 0 10px;
}
.paramsConfig {
  padding-bottom: 200px;
}

.box-card {
  margin-bottom: 10px;
}
.el-icon-circle-plus-outline {
  cursor: pointer;
}

.nature::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 3px; /*高宽分别对应横竖滚动条的尺寸*/
  height: 15px;
}

.nature::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 8px;
  -webkit-box-shadow: inset 0 0 5px #dcdfe6;
  box-shadow: inset 0 0 3px #dcdfe6;
  background: #dcdfe6;
}

.nature::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  background: #ffffff;
}
</style>

